import request from '@/router/axios';

// ---------- 订单 - 用户 -------------
// 1. 获取订单用户的列表， params = {offerId: offerId}
export const getOfferUserList = (current, size, params) => {
  return request({
    url: '/api/beetles-business/user-offer/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    }
  })
}
// 2. crud用户列表，参考：（/api/system/user.js）
export const getOfferList = (userId, statusList) =>{
  return request({
    url:'/api/beetles-business/offer/get-dropdown-select',
    method:'get',
    params:{
      userId,
      statusList
    }
  })
}


// 3. 为当前订单批量增加用户
export const addOfferUsers = (rows) => {
  return request({
    url: '/api/beetles-business/user-offer/submit',
    method: 'post',
    data: rows
  })
}

// 4. 删除userOffers， ids = userOffer的多个id，用逗号隔开
export const removeUserOffers = (ids) => {
  return request({
    url: '/api/beetles-business/user-offer/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

// 5. 订单用户列表展示下拉框（参考：/api/system/dict.js）：权限下拉框、状态下拉框
// 5.1 权限下拉框：param = {"code": "user_offer_data_permission"}
// 5.2 状态下拉框：param = {"code": "user_offer_status"}

// 6. 修改订单用户列表中的权限、状态: 修改权限时： params = {id: "xx", permission: xx}; 修改状态时： params = {id: "xx", status: xx}
export const updateUserOffers = (data) => {
  return request({
    url: '/api/beetles-business/user-offer/edit',
    method: 'post',
    data: data
  })
}


// ------ 订单 - 用户 - 账户 ----------
//1. 选中用户后展示当前用户底下的账户列表,params = {offerId: "xx", "userId"： "xx"}
export const getUserAccountList = (current, size, params) => {
  return request({
    url: '/api/beetles-business/account-offer/list',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    }
  })
}

// 2. crud账户列表，参考：（/api/business/account.js）

//3. 为当前用户批量增加账户
export const addAccountOffers = (rows) => {
  return request({
    url: '/api/beetles-business/account-offer/submit',
    method: 'post',
    data: rows
  })
}

// 4. 删除AccountOffers， ids = AccountOffer的多个id，用逗号隔开
export const removeAccountOffers = (ids) => {
  return request({
    url: '/api/beetles-business/account-offer/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

// 5. 用户账户列表展示下拉框（参考：/api/system/dict.js）：权限下拉框、状态下拉框
// 5.1 权限下拉框：param = {"code": "user_offer_data_permission"}
// 5.2 状态下拉框：param = {"code": "account_offer_status"}


// 6. 修改订单账户列表中的权限: params = {id: "xx", permission: xx};
export const updateAccountOffers = (data) => {
  return request({
    url: '/api/beetles-business/account-offer/edit',
    method: 'post',
    data: data
  })
}

/**
 * 外部分享 获取代理商列表
 */
export const getSelectAgency = (offerId) =>{
  return request({
    url:'/api/beetles-business/offer/select-agency',
    method:'get',
    params:{
      offerId
    }
  })
}

/**
 * 外部分享,根据offerId 获取投放信息(类型)
 */
export const getOfferType = (offerId) =>{
  return request({
    url:'/api/beetles-business/offer/get-offer-type-select',
    method:'get',
    params:{
      offerId
    }
  })
}

/**
 * 外部分享,获取offer指定类型存在的国家/地区
 */
export const getOfferNation = (offerId,isIos) =>{
  return request({
    url:'/api/beetles-business/offer/get-nation-by-offer-type-select',
    method:'get',
    params:{
      offerId,
      isIos
    }
  })
}

/**
 * 外部分享,获取offer指定类型存在的平台
 */
export const getOfferPlatform = (offerId,isIos) =>{
  return request({
    url:'/api/beetles-business/offer/get-platform-by-offer-type-select',
    method:'get',
    params:{
      offerId,
      isIos
    }
  })
}

/**
 * 外部分享.获取账户列表
 */
export const getExternalAccount = (offerId) =>{
  return request({
    url:'/api/beetles-business/account/select/external-account',
    method:'get',
    params:{
      offerId
    }
  })
}

/**
 * 外部分享 新增
 */
export const shareToAgency = (data) =>{
  return request({
    url:'/api/beetles-business/offer/share-to-agency',
    method:'post',
    data:data
  })
}

/**
 * 外部分享 列表
 */
export const getOutList = (current, size, params) =>{
  return request({
    url: '/api/beetles-business/offer/get-share-page',
    method: 'get',
    params: {
      ...params,
      current,
      size,
    }
  })
}

/**
 * 外部分析 修改状态
 */
export const externalStatus = (agencyTenantId,offerId,status) =>{
  return request({
    url:'/api/beetles-business/offer/external-status',
    method:'put',
    params:{
      agencyTenantId,
      offerId,
      status,
    }
  })
}
/**
 * 外部分享 获取详情账户
 */
export const getShareAccount = (agencyTenantId,offerId) =>{
  return request({
    url:'/api/beetles-business/account/get-share-account',
    method:'get',
    params:{
      agencyTenantId,
      offerId,
    }
  })
}

/**
 * 外部分享,获取代理商详细信息
 */
export const getByAgency = (agencyTenantId)=>{
  return request({
    url:'/api/beetles-business/customer/get-by-agency',
    method:'get',
    params:{
      agencyTenantId
    }
  })
}

export const getShare2advAccount = (current, size, params) => {
  return request({
    url: '/api/beetles-offer/accountshare2adv/get-share2adv-account',
    method: 'post',
    params: {
      current,
      size
    },
    data: params

  })
}


export const getShare2advAccountOuter = (current, size, offerId) => {
  return request({
    url: '/api/beetles-offer/accountshare2adv/get-share2adv-account-outer',
    method: 'post',
    params: {
      current,
      size,
      offerId
    },

  })
}

export const addShare2advAccount = (rows) => {
  return request({
    url: '/api/beetles-offer/accountshare2adv/saveList',
    method: 'post',
    data: rows
  })
}


export const removeShare2advAccount = (offerId,ids) => {
  return request({
    url: '/api/beetles-offer/accountshare2adv/remove',
    method: 'post',
    params: {
      offerId,
      ids,
    }
  })
}

export const confirmShare2advAccount = (param) => {
  return request({
    url: '/api/beetles-offer/accountshare2adv/confirm',
    method: 'post',
    data: param
  })
}

export const updateShare2advAccountPermission = (data) => {
  return request({
    url: '/api/beetles-offer/accountshare2adv/updatePermission',
    method: 'get',
    params: data
  })
}
